This page last changed on Mar 02, 2006 by rossmason.
Mule has an internal notification mechanism which can be used to tap into server notification such as a Component being added, the Model being initialised or the Manager being started. These notifications can be useful to allow custom components such as Agents or Mule managed components to react to change in the server. |
Don't confuse these notifications with service events that mule manages between your components and external applications. These Server Notifications provide notifications between objects that comprise the Mule Server, where as service events are the business operations that your business services process. |
There are currently 10 types of Server Notifications -
- Manager Notification - is fired when state changes on the Mule mananger such as initialising, sarting and stopping.
- Model Notification - is fired when state changes on the Mule Model such as initialising, sarting and stopping or components being registered or unregistered.
- Component Notification - is fire when a particular component is started, stopped, paused, resumed.
- Management Notification - is fired when monitored resources are low (not yet implemented)
- Custom Notification - can be fired by objects themselves to custom notification listeners, and can be used to customise notifications on Agents, Components, connectors etc.
- Admin Notification - is fired when requests are received by the Mule Admin agent. These are usually trigged by MuleClient calls using the RemoteDispatcher, which proxies calls to a remote server.
- Connection Notification - happen when a connector attempts to connect to its underlying resource. Notifications are fired when a connection is made, released or the connection attempt fails.
- Message Notification - These notifications are fire when an event is sent or received in the system. These are very good for tracing, but are not enabled by default as there is a performance impact when using these. Read below to find out how to enable them.
- Security Notification - is fired when a request is denied security access.
- Space Monitor Notification - is fired from space implementations such as JavaSpaces, JCache or the Mule internal space implementaiton when events are fired into or out of a space. See [Spaces] for more information.
To become a server event listener objects can implement one of the following interfaces-
- org.mule.impl.internal.notifications.ManagerNotificationListener
- org.mule.impl.internal.notifications.ModelNotificationListener
- org.mule.impl.internal.notifications.ComponentNotificationListener
- org.mule.impl.internal.notifications.ManagementNotificationListener
- org.mule.impl.internal.notifications.CustomNotificationListener
- org.mule.impl.internal.notifications.AdminNotificationListener
- org.mule.impl.internal.notifications.ConnectionNotificationListener
- org.mule.impl.internal.notifications.MessageNotificationListener
- org.mule.impl.internal.notifications.SecurityNotificationListener
- org.mule.impl.internal.notifications.SpaceMonitorNotificationListener
these all have a single method -
public void onNotification(UMOServerNotification notification);
Depending on the listener implemented only certain events will be received, for example the object implements ManagerNotificationListener only events of type ManagerNotification will be received. Objects can implement more than one listener to receive more types of event.
Listeners can be registered on the UMOManager -
MuleManager.getInstance().registerListener(listener);
Each event has an action code that determines the type of event. The action code can be queried in the onEvent method to determine its type. To have an object do something when the Model initialises -
public class MyObject implements ModelNotificationListener
{
public MyObject()
{
MuleManager.getInstance().registerListener(this);
}
public void onNotification(UMOServerNotification notification)
{
if (notification.getAction() == ModelNotification.MODEL_INITIALISED)
{
system.out.println("The Model is initialised!");
}
}
}
Enabling MessageNotifications
Message Notifications are very useful as they provide a snapshot of all information sent into and out of the the Mule Server. These notifications are fired when ver a message is received or sent. As you can imagine, these additional events will have some impact on performance so they are turned off by default. To enable these events you need to set the enableMessageEvents to true on the <mule-environment-properties> i.e.
<mule-environment-properties enableMessageEvents="true"/>
Firing custom Notifications
Custom Notifications can be fired by objects in Mule to notify custom listeners. For example a discovery Agent might fire a 'Client Found' event when a client connects.
To fire a custom event use -
CustomNotification n = new CustomNotification("Hello");
MuleManager.getInstance().fireNotification(e);
Any objects implementing CustomNotificationListener will receive this event. It's a good idea to extend the CustomNotification and define actions for your custom event type. To use the Discovery Agent example above -
DiscoveryNotification n = new DiscoveryNotification(client, DiscoveryNotification.CLIENT_ADDED);
MuleManager.getInstance().fireNotification(e);
|
Non-system objects in Mule can only fire Custom notifications through the manager, attempting to fire other events such as ModelNotification will cause an UnsupportedOperationException. |
Using Event Subscriptions
You can associate a subscription with an event listener so that only events the match the subscription will be passed to the listener. The subscription is a wildcard String expression that will be matched against the 'Resource ID' of the event (see the next section). So to register interest in Component events where the component is called MyService1 you can use -
MuleManager.getInstance().registerListener(listener, "MyService1");
If you wanted to match all components with Service in the name you can use -
MuleManager.getInstance().registerListener(listener, "*Service*");
Notification payloads
All notifications extend java.util.EventObject and the payload of the object can be accessed using the getSource() method. The following table describes the event payloads for each type of event.
Event |
Payload Type |
Resource ID |
Description |
ManagerNotification |
UMOManager |
Manager ID |
The UMOManager instance. Equivilent to calling MuleManager.getInstance() |
ModelNotification |
UMOModel |
Model Name |
The UMOModel instance on the manager. Equivilent to calling MuleManager.getInstance().getModel() |
ComponentNotification |
UMOComponent |
Component Name |
The component that caused this event to fire |
ManagementNotification |
not implemented |
|
not implemented |
CustomNotification |
Any object |
Any String |
The object type is custom to the object firing the event. |
AdminNotification |
UMOMessage |
The request endpoint |
The Admin request received |
ConnectionNotification |
UMOConnectable |
<connector-name>.receiver(<endpoint-uri>) |
The Message Receiver or message dispatcher that was connected |
MessageNotification |
UMOMessage |
Component name |
The message sent or received |
SecurityNotification |
SecurityException |
The Exception Message |
The security execption that occurred |
SpaceMonitorNotification |
UMOSpace |
Space name |
The space that fired the notification. If there is a data item it will be available on the Notification using SpaceMonitorNotification.getItem() |
Notification Actions
the following describes the actions for each Notification type.
ManagerNotification
Action |
Description |
MANAGER_INITIALISNG |
UMOManager.initialise() has been called but not executed |
MANAGER_INITIALISED |
The UMOManager has been initialised |
MANAGER_STARTING |
UMOManager.start() has been called but not executed |
MANAGER_STARTED |
The UMOManager has been started |
MANAGER_STOPPING |
UMOManager.stop() has been called but not executed |
MANAGER_STOPPED |
The UMOManager has been stopped |
MANAGER_DISPOSING |
UMOManager.dispose() has been called but not executed |
MANAGER_DISPOSED |
UMOManager is disposed |
MANAGER_DISPOSING_CONNECTORS |
Registered connectors are about to be disposed |
MANAGER_DISPOSED_CONNECTORS |
Connectors have been disposed |
ModelNotification
Action |
Description |
MODEL_INITIALISING |
The UMOModel.initialise() has been called but not executed |
MODEL_INITIALISED |
The UMOModel has been initialised |
MODEL_INITIALISING_LISTENERS |
Component Listeners are about to be registered on the connectors |
MODEL_INITIALISED_LISTENERS |
Component Listeners have been registered |
MODEL_STARTING |
UMOModel.start() has been called but not executed |
MODEL_STARTED |
The UMOModel has been started |
MODEL_STOPPING |
UMOModel.stop() has been called but not executed |
MODEL_STOPPED |
The UMOModel has been stopped |
MODEL_DISPOSING |
UMOModel.dispose() has been called but not executed |
MODEL_DISPOSED |
The UMOModel has been disposed |
ComponentNotification
Action |
Description |
COMPONENT_INITIALISED |
The component has been initialised |
COMPONENT_STARTED |
The component has been started |
COMPONENT_STOPPED |
The component has been stopped |
COMPONENT_PAUSED |
The component has been paused |
COMPONENT_RESUMED |
The component has been resumed |
COMPONENT_DISPOSED |
The component has been disposed |
ManagementNotification
Not implemented yet
CustomNotification
Action |
Description |
NULL_ACTION |
An action has not been set on the event |
AdminNotification
Action |
Description |
ACTION_RECEIVE |
Is fired when a remote recieve call is made via the Mule Admin Agent. |
ACTION_DISPATCH |
Is fired when a remote asynchronous 'dispatch' call is made via the Mule Admin Agent. |
ACTION_SEND |
Is fired when a remote synchronous 'send' call is made via the Mule Admin Agent. |
ACTION_INVOKE |
Is fired when a remote call is made directly to a component via the Mule Admin Agent. |
ConnectionNotification
Action |
Description |
CONNECTION_CONNECTED |
Is fired when a connector makes a successful connection to its underlying resource. |
CONNECTION_FAILED |
Is fired when a make an unsuccessful connection attempt. |
CONNECTION_DISCONNECTED |
Is fired when a connector disconnects from its resource. This could be triggered by network failure, Jmx or the server shutting down. |
MessageNotification
Action |
Description |
MESSAGE_RECEIVED |
Is fired when a message is received into the Mule instance. |
MESSAGE_DISPATCHED |
Is fired when a message is dispatched asynchronously from a Mule instance. |
MESSAGE_SENT |
Is fired when a message is sent synchronously from Mule instance. |
MESSAGE_REQUESTED |
Is fired when a message is requested via Mule instance, i.e. calling MuleClient.receive(...) |
SecurityNotification
Action |
Description |
SECURITY_AUTHENTICATION_FAILED |
Is fired when a message is received but authentication of the message failed. |
SpaceNotificationNotification
Action |
Description |
SPACE_CREATED |
Is fired when a new space is created. |
SPACE_DISPOSED |
Is fired when a space is disposed. |
SPACE_ITEM_ADDED |
Is fired when an item is added to the space. |
SPACE_ITEM_REMOVED |
Is fired when an item is removed from the space. |
SPACE_ITEM_EXPIRED |
Is fired when an item in a space expires. |
SPACE_ITEM_MISS |
Is fired when an item is requested from the space byut yeilds no result. |
SPACE_LISTENER_ADDED |
Is fired when a listener is registered for the space. |
SPACE_LISTENER_REMOVED |
Is fired when a listener is unregistered for the space. |
|